﻿using PlutoStudio.Modules;
using System;
using System.Collections.Generic;
using System.Text;
using PlutoStudio.Dependency;
using PlutoStudio.Web.Api.ProxyScripting.Configuration;
using PlutoStudio.Web.Security.AntiForgery;
using PlutoStudio.Web.Configuration;
using PlutoStudio.Configuration.Startup;
using PlutoStudio.Web.Api.ProxyScripting.Generators.JQuery;
using PlutoStudio.Localization.Dictionaries;
using PlutoStudio.Localization.Dictionaries.Xml;

namespace PlutoStudio.Web
{
    /// This module is used to use ABP in ASP.NET web applications.
    /// </summary>
    [DependsOn(typeof(KernelModule))]
    public class WebCommonModule : Module
    {

        /// <inheritdoc/>
        public override void PreInitialize()
        {
            IocManager.Register<IApiProxyScriptingConfiguration, ApiProxyScriptingConfiguration>();
            IocManager.Register<IAntiForgeryConfiguration, AntiForgeryConfiguration>();
            IocManager.Register<IWebEmbeddedResourcesConfiguration, WebEmbeddedResourcesConfiguration>();
            IocManager.Register<IWebCommonModuleConfiguration, WebCommonModuleConfiguration>();

            Configuration.Modules.WebCommon().ApiProxyScripting.Generators[JQueryProxyScriptGenerator.Name] = typeof(JQueryProxyScriptGenerator);
            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    WebConsts.LocalizaionSourceName,
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        typeof(WebCommonModule).Assembly, "PlutoStudio.Web.Localization.WebXmlSource"
            )));

        }

        /// <inheritdoc/>
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(WebCommonModule).Assembly);
        }
    }
}
